package co.yixiang.yshop.module.crm.controller.admin.crmworkwxuser;

import co.yixiang.yshop.framework.common.pojo.CommonResult;
import co.yixiang.yshop.framework.common.pojo.PageResult;
import co.yixiang.yshop.framework.common.util.object.BeanUtils;
import co.yixiang.yshop.module.crm.controller.admin.crmworkwxuser.vo.CrmWorkWxUserPageReqVO;
import co.yixiang.yshop.module.crm.controller.admin.crmworkwxuser.vo.CrmWorkWxUserRespVO;
import co.yixiang.yshop.module.crm.controller.admin.crmworkwxuser.vo.CrmWorkWxUserSaveReqVO;
import co.yixiang.yshop.module.crm.dal.dataobject.crmworkwxuser.CrmWorkWxUserDO;
import co.yixiang.yshop.module.crm.service.crmworkwxuser.CrmWorkWxUserService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.Parameter;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.annotation.Resource;
import jakarta.validation.Valid;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import static co.yixiang.yshop.framework.common.pojo.CommonResult.success;

@Tag(name = "管理后台 - 企业微信员工")
@RestController
@RequestMapping("/crm/work-wx-user")
@Validated
public class CrmWorkWxUserController {

    @Resource
    private CrmWorkWxUserService workWxUserService;

    @PostMapping("/create")
    @Operation(summary = "同步企业微信员工")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-user:create')")
    public CommonResult<Boolean> createWorkWxUser() {
        workWxUserService.createWorkWxUser();
        return success(true);
    }

    @PutMapping("/update")
    @Operation(summary = "更新企业微信员工")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-user:update')")
    public CommonResult<Boolean> updateWorkWxUser(@Valid @RequestBody CrmWorkWxUserSaveReqVO updateReqVO) {
        workWxUserService.updateWorkWxUser(updateReqVO);
        return success(true);
    }

    @DeleteMapping("/delete")
    @Operation(summary = "删除企业微信员工")
    @Parameter(name = "id", description = "编号", required = true)
    @PreAuthorize("@ss.hasPermission('crm:work-wx-user:delete')")
    public CommonResult<Boolean> deleteWorkWxUser(@RequestParam("id") Long id) {
        workWxUserService.deleteWorkWxUser(id);
        return success(true);
    }

    @GetMapping("/get")
    @Operation(summary = "获得企业微信员工")
    @Parameter(name = "id", description = "编号", required = true, example = "1024")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-user:query')")
    public CommonResult<CrmWorkWxUserRespVO> getWorkWxUser(@RequestParam("id") Long id) {
        CrmWorkWxUserDO workWxUser = workWxUserService.getWorkWxUser(id);
        return success(BeanUtils.toBean(workWxUser, CrmWorkWxUserRespVO.class));
    }

    @GetMapping("/page")
    @Operation(summary = "获得企业微信员工分页")
    @PreAuthorize("@ss.hasPermission('crm:work-wx-user:query')")
    public CommonResult<PageResult<CrmWorkWxUserRespVO>> getWorkWxUserPage(@Valid CrmWorkWxUserPageReqVO pageReqVO) {
        return success(workWxUserService.getWorkWxUserPage(pageReqVO));
    }



}